package org.raymond.iworks.study.redis.redisson;

import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
@Slf4j
public class BloomFilterTest {
    public static void main(String[] args) throws Exception {
        test();
    }
    public static void test() throws Exception {
        RedissonClient c = client();
        RBloomFilter<String> bf1 = c.getBloomFilter("myBloomFilter");
        RBloomFilter<String> bf2 = c.getBloomFilter("myBloomFilter");

        bf1.tryInit(10000, 0.0001);
        bf2.add("hello");
        bf2.add("hello1");
        bf2.add("hello2");
        for(int i=0; i<10000; i++) {
            bf2.add("diablo");
        }

        log.info("contains:{}, equals:{}", bf1.contains("hello1"), bf1.equals(bf2));

        log.info("shutdown");
        c.shutdown();
    }

    public static RedissonClient client(){
        Config cfg = new Config();
        cfg.useSingleServer()
                .setAddress("redis://192.168.0.125:6379")
                .setUsername("default")
                .setPassword("123456");
        ;
        RedissonClient client = Redisson.create(cfg);
        return client;
    }
}
